package org.nViron.nvParams;

//~--- non-JDK imports --------------------------------------------------------

import java.util.HashMap;

import org.nViron.nvData.nvDataEntity;
import org.nViron.nvParams.nvContextParamMgr.CONTEXTPARAM;
import org.nViron.nvParams.nvVizParamMgr.VIZPARAM;

/**
 * Manages all the parameter binding rules for each visualization parameter
 * @author Roland Haring <p>
 * <script type="text/javascript" src="http://www.ohloh.net/p/376434/widgets/project_basic_stats.js"></script>
 */
public class nvParamBindingMgr {
    private final HashMap paramBindings = new HashMap();

    public nvParamBindingMgr(nvVizParamMgr vizParamMgr) {
        for (int i = 0; i < vizParamMgr.size(); i++) {
            nvVizParam vizParam = (nvVizParam) vizParamMgr.get(i);

            paramBindings.put(vizParam.getKind(), new nvParamBinding(vizParam.getKind()));
        }
    }

    public void addParamBinding(nvParamBinding binding) {
        paramBindings.put(binding.getKind(), binding);
    }

    public nvParamBinding getParamBinding(VIZPARAM param) {
        nvParamBinding paramBinding = (nvParamBinding) paramBindings.get(param);

        return paramBinding;
    }

    public float getValueFor(VIZPARAM param, nvDataEntity entity) {
        nvParamBinding paramBinding = (nvParamBinding) paramBindings.get(param);

        if (paramBinding != null) {
            return paramBinding.getValueFor(entity);
        }

        return 0.0f;
    }

    public boolean isRelatedTo(CONTEXTPARAM contextParam, VIZPARAM vizParam) {
        nvParamBinding paramBinding = (nvParamBinding) paramBindings.get(vizParam);

        if (paramBinding != null) {
            return paramBinding.usesContextParam(contextParam);
        }

        return false;
    }

    public void removeBinding(VIZPARAM param) {
        paramBindings.remove(param);
    }
}



